<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:key name="nodes" match="node" use="@id"/>
<xsl:template match="/">
    <html>
        <head>
            <title>Taxonomy</title>
        </head>
        <body>
		<h1>Significant properties </h1>
		<table width="100%"  border="0" cellspacing="4" cellpadding="0">
			<tbody>
				<tr>
					<td valign="top" width="30%"  >
						<a name="toc"/>
						<xsl:apply-templates mode="toc"/>
					</td>
				            <td bgcolor="#006600" width="2"><xsl:text> </xsl:text></td>
				            <td bgcolor="#ffffff"><xsl:apply-templates mode="text"/></td>
				            
				</tr>
			</tbody>
		</table>
        </body>
        </html>
</xsl:template>


    
    
  <xsl:template match="node" mode="toc">
         <a name="TOC"/>
                      <xsl:choose>
                          <xsl:when test="@id">
                              <a href="#{@id}">
                                    <xsl:value-of select="@id"/>
                                  <xsl:text>: </xsl:text>
                                  <xsl:value-of select="@label"/>
                              </a>
                              <br/>
                          </xsl:when>
                          <xsl:otherwise>
                              <a href="#{generate-id()}">
                                  <xsl:value-of select="@label"/>
                              </a>
                              <br/>
                          </xsl:otherwise>
                      </xsl:choose>
      
    
		<xsl:apply-templates mode="toc" select="isComposedBy"/>
  </xsl:template>
    
    <xsl:template match="node" mode = "text">
      
        
       
        
    
        <h2>
            <xsl:choose>
                <xsl:when test="@id"><a name="{@id}"/></xsl:when>
                <xsl:otherwise><a name ="{generate-id()}"/></xsl:otherwise>
            </xsl:choose>
            
            <xsl:value-of select="@id"/>
             - 
            <xsl:value-of select="@label"/>
        </h2>
        <h5>
            Path: 
            <br/>
            <xsl:for-each select="ancestor-or-self::node">
                <xsl:value-of select="@label"/>
                <xsl:text>/</xsl:text>
            </xsl:for-each>
        </h5>
        <xsl:if test="hasNote">
          <h8>
              <b>Note</b> (type: <xsl:value-of select="hasNote/@type"/>)
              <xsl:value-of select="hasNote"/>              
          </h8>
            </xsl:if>
        <xsl:if test="isComposedBy">
        <h3>Is composed by: </h3>
        </xsl:if>
        <ul>
           
               <xsl:for-each select="isComposedBy/node">
                   <li>
                       <xsl:choose>
                           <xsl:when test ="@id"> <a href="#{@id}"><xsl:value-of select="@label"/></a></xsl:when>
                           <xsl:otherwise> <a href="#{generate-id()}"><xsl:value-of select="@label"/></a></xsl:otherwise>
                       </xsl:choose>
                           
                   </li>       
               </xsl:for-each>
        </ul>
        <xsl:if test="isRelatedTo">
            <h3>Is related to: </h3>
            <ul>
                <xsl:for-each select="isRelatedTo/node">
                    <li> <a href="#{@id}"> <xsl:value-of select="key('nodes',@id)/@label"/> </a></li>
                </xsl:for-each>
            </ul>
        </xsl:if>
        <br/>
        <h5>
        <xsl:if test="ancestor::node">

                [<a href="#{ancestor::node[1]/@id}">Back to parent</a>]
        </xsl:if>
            [<a href="#toc">TOC</a> ] </h5>
            <br/>
            <hr/>
        <xsl:apply-templates select="isComposedBy" mode="text"/>
        
    </xsl:template>
    
    
</xsl:stylesheet>
